import axios, { AxiosRequestConfig } from "axios";

// console.log(import.meta.env.VITE_APP_API);

const request = axios.create({
  baseURL: import.meta.env.VITE_APP_API,
  timeout: 10000,
});

request.interceptors.request.use(
  function (config) {
    if (localStorage.getItem("token")) {
      config.headers!.token = localStorage.getItem("token") as string;
    }
    // if (localStorage.getItem("userId")) {
    //   config.headers!.userTempId = localStorage.getItem("userId") as string;
    // }
    return config;
  },
  function (err) {
    return Promise.reject(err);
  }
);

request.interceptors.response.use(
  function (response) {
    if (response.status === 200) {
      return response.data;
    }
    return response;
  },
  function (err) {
    return Promise.reject(err);
  }
);

export default request;
